<template>
    <div style="width:100%;height:100%;overflow:hidden">
        <weui-cell :list="cell_0_list" @on-click="on_cell_0_click">
        </weui-cell>
        <weui-input :list="input_0_list" title="" :show_more="false" :tips="null" agreement_name=""
                    :more_label="null">
            <weui-button slot="button" type="primary" :is_disable="!input_0_list[0].value"
                        @on-click="on_button_0_click">确定
            </weui-button>
        </weui-input>
    </div>
</template>
<script>
import WeuiCell from '../vue2componentSet/src/components/WeuiCell'
import WeuiInput from '../vue2componentSet/src/components/WeuiInput'
import WeuiButton from '../vue2componentSet/src/components/WeuiButton'
import global from '../lib/global'
import axios from 'axios'

export default {
    components: {
        WeuiCell, WeuiInput, WeuiButton
    },
    data() {
        return {
            cell_0_list: [],
            taobaoTradeParentId: '',
            auctionId: '',
            orderId: '',
            tradeParentId: '',
            itemId: '',
            input_0_list: [{
                type: 'tel',
                value: '',
                label: '自己输入'
            }]
        }
    },
    mounted() {
        if (!this.$store.state.admin) {
            this.$router.goback()
            return
        }
        location.hash.split('?')[1] && location.hash.split('?')[1].split('&').forEach(kv => {
            this[kv.split('=')[0]] = decodeURIComponent(kv.split('=')[1])
        })
        axios.post(global.server + 'getCustomerForBill.do', {
            taobaoTradeParentId: this.taobaoTradeParentId,
            auctionId: this.auctionId,
            orderId: this.orderId,
            tradeParentId: this.tradeParentId,
            itemId: this.itemId
        }).then(result => {
            const obj = result.data
            if (obj.result == -1) {
                this.$store.commit('toast', {
                    type: 'warn',
                    content: obj.msg
                })
            } else if (obj.result == 0) {
                obj.isAdmin && this.$store.commit('admin_login', null)
                this.$router.goback()
            } else {
                this.cell_0_list = []
                obj.customer_phone.forEach((item, index) => {
                    this.cell_0_list.push({
                        value: item,
                        desc: obj.log_time[index]
                    })
                })
            }
        })
    },
    methods: {
        on_cell_0_click(index) {
            this.show_confirm_dialog(this.cell_0_list[index].value)
        },
        on_button_0_click(phone) {
            if (!this.input_0_list[0].value)
                return
            this.show_confirm_dialog(this.input_0_list[0].value)
        },
        show_confirm_dialog(phone) {
            this.$store.commit('dialog', {
                is_show: true,
                content: '确定分配给' + phone + '吗？',
                list: ['取消', '确认'],
                'on-click': (index) => {
                    this.$store.commit('dialog', {
                        is_show: false
                    })
                    if (index == 1) {
                        axios.post(global.server + 'setCustomerForBill.do', {
                            taobaoTradeParentId: this.taobaoTradeParentId,
                            orderId: this.orderId,
                            customer_phone: phone,
                            tradeParentId: this.tradeParentId
                        }).then(result => {
                            const obj = result.data
                            if (obj.result == -1) {
                                this.$store.commit('toast', {
                                    type: 'warn',
                                    content: obj.msg
                                })
                            } else if (obj.result == 0) {
                                obj.isAdmin && this.$store.commit('admin_login', null)
                                this.$router.goback()
                            } else {
                                this.$router.goback()
                            }
                        })
                    }
                }
            })
        }
    }
}
</script>